package com.albertyjz.juc;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {
    public static void closeDoor(){
        for(int i=1;i<=6;i++){
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"\t离开教室");
            },String.valueOf(i)).start();
        }
        System.out.println(Thread.currentThread().getName()+"\t关门");
    }
    public static void main(String[] args) throws InterruptedException {
        //其他线程调用countdownlatch方法会将计数器减1（调用countdown方法的线程不会阻塞），当计数器变为0时，被await阻塞的方法会被唤醒，继续执行。
        CountDownLatch countDownLatch=new CountDownLatch(9);
        for(int i=1;i<=6;i++){
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"\t离开教室");
                countDownLatch.countDown();
            },String.valueOf(i)).start();
        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName()+"\t关门!");
    }
}
